package com.naiterui.ehp.bs.pharmacist.interceptor;

import com.naiterui.ehp.bp.support.security.PharmacistLoginInterceptor;
import com.naiterui.ehp.bp.support.security.SettingConfig;
import com.naiterui.ehp.bp.utils.context.SpringContextHolder;
import com.naiterui.ehp.bs.pharmacist.service.security.ISecurityService;
import com.naiterui.ehp.bs.pharmacist.service.security.impl.PharmacistSecurityServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginInterceptor extends PharmacistLoginInterceptor {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginInterceptor.class);


    @Override
    protected boolean verifyToken(HttpServletRequest request, HttpServletResponse response) throws
            NumberFormatException,
            IOException {
        String pharmacistId = request.getParameter(SettingConfig.PHARMACIST_ID);
        String token = request.getParameter(SettingConfig.TOKEN);
        
        ISecurityService securityService = SpringContextHolder.getBean(PharmacistSecurityServiceImpl.class);
        return securityService.saveCheckToken(pharmacistId, token, response);
    }


}